let form = layui.form
// let data = $(this).serializeArray()
//点击编辑,跳转到编辑页面

let id = location.search.substr(4)

$.ajax({
    type: "get",
    url: "/admin/users/" + id,
    success: function (res) {
        if (res.status === 0) {

            let data = {
                username: res.data.username,
                nickname: res.data.nickname,
                email: res.data.email
            }

            form.val("formTest", data);
        }
    }

})

//点击提交,提示修改列表 并且渲染
$(".layui-form").on("submit", function (e) {
    e.preventDefault()
    let data1 = $(".layui-form").serialize()
    let data = "id=" + id + "&" + data1
    $.ajax({
        type: "PUT",
        url: "/admin/users",
        data,
        success: function (res) {

            if (res.status === 0) {
                layer.msg(res.message, {
                    time: 2000
                }, function () {

                    location.href = "./user.html"
                })
            } else {
                layer.msg(res.message)
            }
        }

    })
})

//表单验证